# 字符串方法

# 常量
from string import digits, ascii_letters, ascii_lowercase, ascii_uppercase, printable, punctuation, whitespace, \
    hexdigits, octdigits

print("-" * 20)
print(f'digits={digits}')
print(f'ascii_letters={ascii_letters}')
print(f'ascii_lowercase={ascii_lowercase}')
print(f'ascii_uppercase={ascii_uppercase}')
print(f'printable={printable}')
print(f'punctuation={punctuation}')
print(f'hexdigits={hexdigits}')
print(f'octdigits={octdigits}')
print(f'whitespace={whitespace}')
print("-" * 20)

# 方法
# center
print("The Middle by Jimmy Eat World".center(50))
print("The Middle by Jimmy Eat World".center(50, '*'))
#           The Middle by Jimmy Eat World
# **********The Middle by Jimmy Eat World***********

# find
title = "Monty Python's Flying Circus"
print(title.find("Monty"))  # 0
print(title.find("Python"))  # 6
print(title.find("abc"))  # -1

subject = '$$$ Get rich now!!! $$$'
print(subject.find("$$$"))  # 0
print(subject.find("$$$", 1))  # 20
print(subject.find("$$$", 1, 10))  # -1

# join
seq = ['1', "2", "3", "4", "5"]
print(",".join(seq))  # 1,2,3,4,5
seq = '', 'usr', 'bin', 'env'
print('/'.join(seq))  # /usr/bin/env
print('\\'.join(seq))  # \usr\bin\env

# lower  upper title
print('Trondheim Hammer Dance'.lower())  # trondheim hammer dance
print('Trondheim Hammer Dance'.upper())  # TRONDHEIM HAMMER DANCE
print('Trondheim Hammer Dance'.title())  # Trondheim Hammer Dance

# replace
print('This is a test'.replace('is', 'eez'))  # Theez eez a test
print('This is a is test'.replace('is', 'eez'))  # Theez eez a eez test

# split 默认使用空格
print('1+2+3+4+5'.split('+'))  # ['1', '2', '3', '4', '5']
print('/usr/bin/env'.split('/'))  # ['', 'usr', 'bin', 'env']
print('Using the default'.split())  # ['Using', 'the', 'default']

# strip
print(' internal whitespace is kept '.strip())  # internal whitespace is kept
print('*** SPAM * for * everyone!!! ***'.strip(' *!'))  # SPAM * for * everyone

# translate
table = str.maketrans('cs', 'kz')
print(table)  # {99: 107, 115: 122}
print('this is an incredible test'.translate(table))  # thiz iz an inkredible tezt

table = str.maketrans('cs', 'kz', ' ')
print('this is an incredible test'.translate(table))  # thizizaninkredibletezt

# is
print("123".isdigit())
print("abc".isalpha())
print("123abc".isalnum())
print("AAA".isupper())
print("bb".islower())
#
